package vwg.na.vwm.rh.motorsdk.modelo.procesos.daoimpl;

import java.util.List;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import vwg.na.vwm.rh.motorsdk.modelo.procesos.IdeaProceso;
import vwg.na.vwm.rh.motorsdk.modelo.procesos.dao.IdeIdeaCampaignDAO;
import vwg.na.vwm.rh.motorsdk.modelo.procesos.entidadesgrales.IdeCampaign;
import vwg.na.vwm.rh.motorsdk.modelo.procesos.entidadesgrales.IdeIdeaCampaign;
import vwg.na.vwm.rh.rhmotor.modelo.dao.GenericDAO;

@Repository
public class IdeIdeaCampaignDAOImpl extends GenericDAO<IdeIdeaCampaign>
	implements IdeIdeaCampaignDAO {

    @SuppressWarnings("unchecked")
    @Override
    @Transactional(readOnly = true, propagation = Propagation.REQUIRED)
    public List<IdeIdeaCampaign> getCampaignsByIdea(IdeaProceso ideaProceso) {
	return getHibernateTemplate().find(
		"FROM IdeIdeaCampaign as i "
		+ "LEFT JOIN FETCH i.ideCampaign as ic "
		+ "WHERE i.ideaProceso = ? ",
		ideaProceso);

    }

    @Override
    public void deleteByIdeaAndCampaign(IdeaProceso ideaProceso,
	    IdeCampaign ideCampaign) {
	getHibernateTemplate().find("DELETE FROM IdeIdeaCampaign as i"
		+ "WHERE i.ideCampaign = ? and i.ideaProceso = ? ", ideCampaign, ideaProceso);
	
    }
    
    @SuppressWarnings("unchecked")
    @Override
    @Transactional(readOnly = true, propagation = Propagation.REQUIRED)
    public List<IdeIdeaCampaign> existeCampaignByIdea(IdeaProceso ideaProceso,
	    IdeCampaign campaign) {
	return getHibernateTemplate().find("FROM IdeIdeaCampaign as i "
		+ "WHERE i.ideCampaign = ? and i.ideaProceso = ?", campaign, ideaProceso);
	
    }

}
